Repository navigation
dsh-huggingface: size a cached checkpoint for the LOAD, from its files - #19
Merged
Merged
Conversation
The download size only half-answers "should I fetch this?". Once the bytes are on disk the question becomes "will it run here", and every number that decides it is already in the cache. hf_repo now answers it for a cached repo, with no model loaded and no Python: weights = the sum of the weight files params = weights / bytes-per-parameter KV/token = 2 x layers x kv_heads x head_dim x dtype_bytes total = weights + KV x context + max(512 MiB, 10% of the weights) Pass freeBytes and the context table gets a FITS column; pass contexts to choose the lengths. A repo that is not cached, or is metadata only, gets no estimate and says why - the attention heads live in a config that was never downloaded. The dtype is read from the SAFETENSORS HEADER, not from config.json, and that is a measured finding rather than a preference: sentence-transformers/all-mpnet-base-v2 states no torch_dtype and stores F32, so an fp16 assumption reported ~219M parameters for a 109M model and HALF its real KV cache (36 KB/token rather than 72). An fp16 config claiming fp16 weights is now also reported as a disagreement rather than silently believed. Checks: 243 in the package (up from 217) - the arithmetic asserted against exact bytes, an fp32 fixture with a REAL safetensors header, a metadata-only repo with no fit, and a FITS/NO pair. check-node-routes, check-no-secrets, check-scripts all pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
hf_reponow answers the question a download size only half-answers, for anyrepo that is already cached: will it run here?
Read from the files on disk — no model loaded, no Python, no network:
Pass
freeBytesand the context table gains aFITScolumn; passcontextstochoose the lengths; pass
dtypeto override. A repo that is not cached, or ismetadata only, gets no estimate and a sentence saying why — the attention
heads live in a
config.jsonthat was never downloaded.Also folded in from the dropped transformers row: the multilingual
text_confignesting, and the KV formula's grouped-query-attention handling (
num_key_value_headsrather than falling back to all heads).
The finding that came out of testing it
A checkpoint's dtype is in its safetensors HEADER, not in its config. Both the
parameter count and the KV size divide or multiply by bytes-per-parameter, so
The header is a u64 length plus JSON read from the FRONT of the file, so it costs
a few KB of I/O. When a config claims one dtype and the weights are another, the
answer now names the disagreement instead of silently believing the config.
Verification
New assertions: the arithmetic against exact bytes (128 KiB/token for a
32-layer/8-KV-head/head_dim-128 shape), an fp32 fixture with a real safetensors
header, a metadata-only repo with no fit, and a
FITS/NOpair driven byfreeBytes. Live against the real cache: mpnet reports~109M params at float32 (from the safetensors header) · KV 72.0 KB/token.Numbers on the banner
The banner in
assets/vncode-banner6.pngalready carries 35 plugins, 59skills from the previous PR, and that is confirmed against the last cut:
v0.1.5had exactly 33 packages / 51
SKILL.mdfiles, so the convention is packages =plugins, skills =
SKILL.md. This PR adds no package and no skill, so the numbersdo not move — the banner and
assets/banner.htmlare unchanged and correct.